﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using RazakiBLL;
using RazakiBLL.Managers;

namespace RazakiSite.PagesNews
{
    public partial class NewsView : BasePage
    {
        public int NewId
        {
            get { return UtilitiesUI.GetQueryString<int>("newid", false); }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (IsPostBack)
                return;

            ConfigControls();
        }

        protected override void ConfigControls()
        {
            UowRazaki uowRazaki = new UowRazaki();
            var newInfo = uowRazaki.NewRepository.GetNewInfoById(uowRazaki.NewTagRepository, NewId);

            uowRazaki.NewRepository.ViewCountPlusOne(NewId);
            uowRazaki.Save();

            lblTitle.Text = newInfo.Title;
            lblTag.Text = newInfo.TagQueueDesc;
            lblViewCount.Text = newInfo.ViewCount.ToString();
            lblDate.Text = UtilitiesBLL.GetPersianDate(newInfo.UpdateDate, true);
            ltrText.Text = newInfo.Text;
            lblUser.Text = UtilitiesUI.GetFullNameOfUser(newInfo.UserId);
            lblSource.Text = newInfo.Publisher;

            if (Page.User.Identity.IsAuthenticated)
            {
                if (UtilitiesUI.IsIdForCurrentUser((Guid) newInfo.UserId) || UtilitiesUI.IsAdmin())
                {
                    NewsActions.ShowDelete = true;
                }
            }

            NewsActions.NewTagFirstParentId =
                uowRazaki.NewTagRepository.GetFirstParentByLastChildId((short)newInfo.TagId).Id;
        }
    }
}